// pages/detailed/detailed.js
import { getArcDetail, getsingle} from '../../utils/api.js';
var WxParse = require('../../wxParse/wxParse.js')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    arcDeatail:{},
    content:'',
    newsList:[]
  },
  getsph(e) {
    let video_id = this.data.arcDeatail.video_id
    let videoId = wx.getStorageSync('videoId')
    wx.openChannelsActivity({
      finderUserName: videoId,
      feedId: video_id,
      success: (res) => {
        console.log(res)
      },
      fail: (err) => {
        console.log(err)
      }
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    if (options.id && options.list_id){
      getArcDetail({ id: options.id, list_id: options.list_id }).then(res => {
        wx.setNavigationBarTitle({
          title: res.data.arc.title
        })
        var article = res.data.arc.content;//article是取到的数据 
        var that = this; 
        WxParse.wxParse('article', 'html', article, that, 5);
        this.setData({
          arcDeatail: res.data.arc,
          // content: res.data.arc.content.replace(/\<img/gi, '<img style="max-width:100%;height:auto"').replace(/\img>/gi, 'img>').replace(/\<figure class="image">/gi, '').replace(/\<\/figure>/gi, ''),
          newsList: res.data.arc_list
        })
      })
    }else{
      getsingle({ list_id: options.id}).then(res=>{
        var article = res.data.page_content;//article是取到的数据 
        var that = this;
        WxParse.wxParse('article', 'html', article, that, 5);
        wx.setNavigationBarTitle({
          title: res.data.name
        })
        this.setData({
          arcDeatail:{
            title: res.data.name,
            publish_time: res.data.created_at,
            cover_img: res.data.cover_img,
            video_id: res.data.video_id
          },
          // content: res.data.page_content.replace(/\<img/gi, '<img style="max-width:100%;height:auto"').replace(/\img>/gi, 'img>').replace(/\<figure class="image">/gi, '').replace(/\<\/figure>/gi, '')
        })
      })
    }
    
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})